import service from "../interceptor.ts";
import {Captcha, LoginInfo} from "./types.ts";
import {AxiosPromise} from "axios";

export function getCaptchaApi():AxiosPromise<Captcha>{
    return service({
        url: "api/auth/captcha",
        method:"GET"
    })
}

export function loginApi(param: LoginInfo) {
    let formData = new FormData();
    formData.append("username", param.username)
    formData.append('password', param.password)
    formData.append('captchaKey', param.captchaKey)
    formData.append('captchaCode', param.captchaCode)
    return service({
        url: "api/auth/login",
        method: "POST",
        data: formData,
        headers: {
            "Content-Type": "multipart/form-data",
        },
    });
}